package com.sk.bilibili.service;

import com.sk.bilibili.other.R;
import com.sk.bilibili.property.MinioProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 邵康
 * @date 2021/12/5 21:41
 */
@Service
public class SingletonService {

    @Autowired
    private MinioProperty minioProperty;
    @Autowired
    private MinioService minioService;
    private static final String LIVE_BG="singleton/liveBg.jpg";
    private static final String ANNOUNCEMENT_BG="singleton/announcementBg.jpg";
    private static final String ANNOUNCEMENT_URL="singleton/announcement.html";

    //  id为0  就是背景图片
    public R<String> getLiveBg() {
        return R.success(minioProperty.getBasePath()+LIVE_BG);
    }

    public R<Void> updateLiveBg(MultipartFile liveBg) {
        minioService.uploadStream(liveBg,LIVE_BG);
        return R.success();
    }

    public R<Map<String, Object>> getAnnouncement() {
        Map<String,Object> map=new HashMap<>();
        map.put("background",minioProperty.getBasePath()+ANNOUNCEMENT_BG);
        map.put("url",minioProperty.getBasePath()+ANNOUNCEMENT_URL);
        return R.success(map);
    }

    public R<Void> updateAnnouncementBg(MultipartFile announcementBg) {
        minioService.uploadStream(announcementBg,ANNOUNCEMENT_BG);
        return R.success();
    }

    public R<Void> updateAnnouncement(MultipartFile announcement) {
        minioService.uploadStream(announcement,ANNOUNCEMENT_URL);
        return R.success();
    }

}
